package com.devsoft.foodflip;

import java.util.Date;


public class Timer {
	//To handle in-game events like power-ups
	private long duration;
	private long start_time;
	private boolean is_Running;
	
	public Timer(long milisecs){
		this.duration=milisecs;
		this.start_time=0;
		this.is_Running=false;
	}
	
	public void start(){
		this.start_time = new Date().getTime();
		this.is_Running = true;
	}
	
	public long getCurrentTime(){
		return (new Date().getTime() - start_time);
	}

	public void printCountdown(){
		System.out.print((this.duration-this.getCurrentTime())/60000);//Minutes
		System.out.print(":");
		System.out.print(((this.duration-this.getCurrentTime())/1000)%60);//Seconds
		System.out.print(":");
		System.out.print((this.duration-this.getCurrentTime())%1000);//Milliseconds
		System.out.println();
	}

	public void printTime(){
		System.out.print(this.getCurrentTime()/60000);//Minutes
		System.out.print(":");
		System.out.print((this.getCurrentTime()/1000)%60);//Seconds
		System.out.print(":");
		System.out.print(this.getCurrentTime()%1000);//Milliseconds
		System.out.println();
	}
	
	public boolean running(){
		if(this.getCurrentTime() >= duration){
			is_Running = false;
		}
		return is_Running;
	}
	
}
